package com.rabit.test;

public class TradionalThreadSynchronized {

	public static void main(String[] args) {
		new TradionalThreadSynchronized().init();
	}

	private void init() {
		final Outputer outputer = new Outputer();
		new Thread(new Runnable() {

			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
						outputer.output2("zhangsan");
				}
			}
		}).start();
		new Thread(new Runnable() {

			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
						outputer.output2("lixiaoming");
				}
			}
		}).start();
	}

	class Outputer {
		public void output(String name) {
			int length = name.length();
			synchronized (this) {
				for (int i = 0; i < length; i++) {
					System.out.print(name.charAt(i));
				}
				System.out.println();
			}
			
		}
		
		public synchronized void output2(String name) {
			int length = name.length();
				for (int i = 0; i < length; i++) {
					System.out.print(name.charAt(i));
				}
				System.out.println();
			}
	}
}
